package model

import (
	"fmt"
	"gorm.io/gorm"
	"time"
)

type MajorNew struct {
	BoyRate       any `json:"boy_rate" gorm:"type:varchar(255); default:null"`
	Degree        any `json:"degree" gorm:"type:varchar(255); default:null"`
	Fivesalaryavg any `json:"fivesalaryavg" gorm:"type:varchar(255); default:null"`
	GirlRate      any `json:"girl_rate" gorm:"type:varchar(255); default:null"`
	Hightitle     any `json:"hightitle" gorm:"type:varchar(255); default:null"`
	Level1        any `json:"level1" gorm:"type:varchar(255); default:null"`
	Level1Name    any `json:"level1_name" gorm:"type:varchar(255); default:null"`
	Level2        any `json:"level2" gorm:"type:varchar(255); default:null"`
	Level2Name    any `json:"level2_name" gorm:"type:varchar(255); default:null"`
	Level3        any `json:"level3" gorm:"type:varchar(255); default:null"`
	Level3Name    any `json:"level3_name" gorm:"type:varchar(255); default:null"`
	LimitYear     any `json:"limit_year" gorm:"type:varchar(255); default:null"`
	Name          any `json:"name" gorm:"type:varchar(255); default:null"`
	Rank          any `json:"rank" gorm:"type:varchar(255); default:null"`
	Salaryavg     any `json:"salaryavg" gorm:"type:varchar(255); default:null"`
	Spcode        any `json:"spcode" gorm:"type:varchar(255); default:null"`
	SpecialID     any `json:"special_id" gorm:"type:varchar(255); default:null"`
	ViewMonth     any `json:"view_month" gorm:"type:varchar(255); default:null"`
	ViewTotal     any `json:"view_total" gorm:"type:varchar(255); default:null"`
	ViewWeek      any `json:"view_week" gorm:"type:varchar(255); default:null"`
	CreatedAt     time.Time
	UpdatedAt     time.Time
	DeletedAt     gorm.DeletedAt `gorm:"index"`
}

func FirstByNameMajorNew(where MajorNew) (first MajorNew) {
	db.Where(&where, "spcode", "hightitle").First(&first)
	return
}

func CreateMajorNew(majorNew MajorNew) {
	db.Create(&majorNew)
}

func UpdateMajorNew(majorNew MajorNew) {
	db.Where(&majorNew, "spcode", "hightitle").Updates(majorNew)
}

func UpdateOrCreateMajorNew(majorNew MajorNew) {
	isExist := FirstByNameMajorNew(majorNew)
	if isExist.Name == nil {
		fmt.Println("创建....................................")
		CreateMajorNew(majorNew)
	} else {
		fmt.Println("修改....................................")
		UpdateMajorNew(majorNew)
	}
}
